package com.songshuai.webapi.login.utils;


import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Auther: Administrator
 * @Date: 2018/11/14 0014 14:26
 * @Description:
 */
public class RegexUtil {
    /**
     * 验证手机
     */
    private static Pattern patternPhone = Pattern.compile("^1[0-9]{10}$");
    /**
     * 验证邮箱
     */
    private static Pattern patternMail=Pattern.compile("^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$");

    /**
     * 验证电话或邮箱
     * @param inputValu
     * @return
     */
    public static Integer validPhoneOrMail(String inputValu){
        Integer retData=0;
        if(inputValu==null||inputValu.length()==0){
            return retData;
        }
        Matcher matcher= patternPhone.matcher(inputValu);
        if(matcher.matches()){
            return RegexTypeEnum.TelePhone.getCode();
        }
        matcher=patternMail.matcher(inputValu);
        if(matcher.matches()){
            return RegexTypeEnum.EMail.getCode();
        }
        return retData;
    }
}
